#ifndef MAP_H_
#define MAP_H_

#include <fstream>
#include <map>

#include "collisionbox.h"
#include "entity.h"
#include "smartcontainer.h"
#include "framescene.h"

class CTile : public CEntity
{
	
	std::string m_TileName;
	int m_TileType;
	
public:
	
	inline void SetName( std::string s )
	{
		
		m_TileName = s;
		
	}
	
	
	inline const std::string & GetName()
	{
		
		return m_TileName;
		
	}
	
	inline void SetType( int t )
	{
		
		m_TileType = t;
		
	}
	
	inline const int & GetType()
	{
		
		return m_TileType;
		
	}
	
	void HandleEntityCollision( CEntity * );

	
};

class CMapRegion
{
	
	CFrameBufferObject * m_pFBO;
	
	Vector2D m_Pos, m_Size;
	
public:
	
	CMapRegion();
	~CMapRegion();
	
	void SetRegionData( CFrameBufferObject *, Vector2D, Vector2D );
	
	void Draw( const Vector2D & );
	
};

class CMap : public CEntity
{

private:

	CSmartVector< CMapRegion > m_vRegions;
	CSmartVector< CTile > m_vTiles;
	CSmartVector< CCollisionBox > m_vCollisionMap;
	
	int m_MapVersion;
	
	int m_MapWidth, m_MapHeight;
	int m_PixelWidth, m_PixelHeight;
	
	Vector2D m_TopLeftPoint;
	
public:
	
	bool EntityCollidingWithMap( CEntity * , CCollisionReport & );
	
	inline const Vector2D & GetTopLeftPoint()
	{
		
		return m_TopLeftPoint;
		
	}
	
	inline int GetMapWidth()
	{
		return m_MapWidth; 
	}
	
	inline int GetMapHeight()
	{
		return m_MapHeight;
	}
	
	inline int GetMapPixelWidth()
	{
		return m_PixelWidth;	
	}
	
	inline int GetMapPixelHeight()
	{
		return m_PixelHeight;	
	}
	
	void DrawTilesAt( Vector2D, Vector2D );
	void DrawOutline();
	void DrawFrameBufferObjects( const Vector2D & );
	void DrawAndCull( const Vector2D & );
	void Draw();
	
	void Load( std::string );
	
	virtual ~CMap();

};

#endif
